package com.ruoyi.framework.aspectj;

import com.ruoyi.common.annotation.TruncateSize;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;

@Aspect
@Component
public class TruncateSizeAspect {

    @Around("execution(* set*(..)) && args(value) && @annotation(truncateSize)")
    public Object around(ProceedingJoinPoint joinPoint, String value, TruncateSize truncateSize) throws Throwable {
        System.out.println("----------------------TruncateSizeAspect-------------------------");
        if (value != null && value.length() > truncateSize.max()) {
            value = value.substring(0, truncateSize.max());
        }
        return joinPoint.proceed(new Object[]{value});
    }
}
